package org.ruizhijie;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.ruizhijie.config.SystemConfig;
import org.ruizhijie.run.InPort;
import org.ruizhijie.run.OutPort;
import org.ruizhijie.topic.TopicQueue;
import org.ruizhijie.topic.i.impl.InPortPublisherImpl;

public class Main {
	public static Properties properties;
	
	public static void main(String[] args) {
		loadProperties();
		
		SystemConfig.init(properties);
		
		TopicQueue tq = new TopicQueue();
		
		
		// 初始化输入
		new Thread(new InPort(new InPortPublisherImpl(tq), SystemConfig.inPort)).start();

		// 初始化输出
		new Thread(new OutPort(tq,SystemConfig.inPort+"",SystemConfig.outHost,SystemConfig.outPort)).start();
		
		// 初始化输出
		new Thread(new OutPort(tq,SystemConfig.inPort+"",SystemConfig.serverHost,SystemConfig.serverPort)).start();
	}
	
	

	private static void loadProperties() {
		String rootPath = System.getProperty("user.dir").replace("\\", "/");
		
		properties = new Properties();
		try {
			System.err.println(rootPath);
			InputStream inputStream = new FileInputStream(rootPath+"/config.properties");
			properties.load(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
